@extends('layout.default')

@section('layout.content')

  <div class="row">    
    <div class="col-xs-12">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
          <tr>
            <th class="align-middle" style="min-width:240px;">活动名称</th>
            <th class="center">题型</th>
            <th class="center">题数</th>
            <th class="center">答题</th>
            <th class="center">状态</th>
            <th class="align-left">UUID</th>
            <th class="align-right" style="width:110px;">创建日期</th>
          </tr>
          </thead>
          <tbody>
            <tr class="bank">
              <td class="align-middle">
                  <a href="javascript:;" class="edit-act" data-tid="{{$topic->id}}"><i class="ace-icon fa fa-edit"></i></a>
                  <a href="{{route('act.question.index', $topic->id)}}">{{ $topic->name }}</a>
              </td>
              <td class="center">{!! $topic->present()->tType !!}</td>
              <td class="center">{{ $topic->questions->count() }}</td>
              <td class="center">{{ $topic->joins->count() }}</td>
              <td class="center">{!! $topic->present()->tStatus !!}</td>
              <td class="align-left">{{ $topic->token }}</td>
              <td class="align-right"><span class="grey smaller-80">{{ date('Y-m-d',strtotime($topic->created_at)) }}</span></td>
          
            </tr>
          </tbody>
      </table>
    </div>

  </div>

  <div class="row">
    <div class="col-xs-12 align-right">      
        <button class="btn btn-success create-question-s {{$topic->type==1?'':'disabled'}}" data-tid="{{$topic->id}}" {{$topic->type==1?'':'disabled'}}><i class="ace-icon fa fa-plus"></i> 选择题</button>    
        <button class="btn btn-danger create-question-b {{$topic->type==2?'':'disabled'}}" data-tid="{{$topic->id}}" {{$topic->type==2?'':'disabled'}}><i class="ace-icon fa fa-plus"></i> 填空题</button>    
    </div>
  </div><!-- /.row -->
  <div class="row">
    <div class="col-xs-12"><h5 class="header smaller lighter blue">题库</h5></div>
    <div class="col-xs-12 col-md-6">      
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
          <tr>
            <th class="align-left">题目</th>
            <th class="align-left" style="width:60px;">类型</th>
          </tr>
        </thead>
        <tbody>
          @foreach ($questions as $i=>$question)
          <?php
              if($i == $paging) break;
              $question = $questions->shift();
          ?>
          <tr class="bank">
            <td class="align-left">
              <a href="javascript:;" class="edit-question" data-type="{{$question->type}}" data-tid="{{$question->topic_id}}" data-qid="{{$question->id}}">
                {{ $question->title }}</a>
            </td>
            <td class="align-left">{!! $question->present()->qType !!}{!!$question->type==1?$question->present()->qSingle:''!!}</td>
          </tr>
          @endforeach
        </tbody>
      </table>     

    </div>

    <div class="col-xs-12 col-md-6">
      <table class="table table-hover table-striped table-bordered nonborder">
        <thead>
          <tr>
            <th class="align-left">题目</th>
            <th class="align-left" style="width:60px;">类型</th>
          </tr>
        </thead>
        <tbody>
          @foreach ($questions as $question)         
          <tr class="bank">
            <td class="align-left">
              <a href="javascript:;" class="edit-question" data-type="{{$question->type}}" data-tid="{{$question->topic_id}}" data-qid="{{$question->id}}">
                {{ $question->title }}</a>
            </td>
            <td class="align-left">{!! $question->present()->qType !!}{!!$question->type==1?$question->present()->qSingle:''!!}</td>
          </tr>
          @endforeach
        </tbody>
      </table>
    </div>
  </div><!-- /.row -->
  
    
@stop
@section('javascript')  
<script type="text/javascript">
$(function () {
      
    $('.create-question-s').on('click', function(e) {
        var tid = $(this).data('tid');
        layer.open({
          type: 2,
          title: '新增选择题',
          area: ['540px', '650px'],
          shade: 0.8,
          content:"/act/question/"+tid+"/create/select",
        });
    });

    $('.create-question-b').on('click', function(e) {
        var tid = $(this).data('tid');
        layer.open({
          type: 2,
          title: '新增填空题',
          area: ['540px', '650px'],
          shade: 0.8,
          content:"/act/question/"+tid+"/create/blank",
        });
    });

    $('.edit-question').on('click', function(e) {
        var that = $(this);
        var tid = that.data('tid');
        var qid = that.data('qid');
        var type = that.data('type');
        var jump;
        jump = type == 1?'select':'blank';
        
        layer.open({
          type: 2,
          title: '修改题目',
          area: ['540px', '650px'],
          shade: 0.8,
          content:"/act/question/"+tid+"/edit/"+qid+"/"+jump,
        });
    });


});
</script>
@stop
